﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Collections;
using System.Web.UI.WebControls;
using Lib.Common;


namespace Lib.Utility
{
   public class ObjMiscUtility
    {
       #region Thay thế ký tự (sử dụng trong việc rewrite URL)
       public static string Replace(string dauvao)
       {
           string daura;
           daura = dauvao.Trim();
           daura = dauvao.ToLower();
           daura = daura.Replace(" ", "-");
           daura = daura.Replace("đ", "d");
           daura = daura.Replace("â", "a");
           daura = daura.Replace("ấ", "a");
           daura = daura.Replace("ầ", "a");
           daura = daura.Replace("ẩ", "a");
           daura = daura.Replace("ẫ", "a");
           daura = daura.Replace("ậ", "a");
           daura = daura.Replace("á", "a");
           daura = daura.Replace("à", "a");
           daura = daura.Replace("ả", "a");
           daura = daura.Replace("ã", "a");
           daura = daura.Replace("ạ", "a");
           daura = daura.Replace("ă", "a");
           daura = daura.Replace("ắ", "a");
           daura = daura.Replace("ằ", "a");
           daura = daura.Replace("ẳ", "a");
           daura = daura.Replace("ẵ", "a");
           daura = daura.Replace("ặ", "a");
           daura = daura.Replace("ó", "o");
           daura = daura.Replace("ò", "o");
           daura = daura.Replace("ỏ", "o");
           daura = daura.Replace("õ", "o");
           daura = daura.Replace("ọ", "o");
           daura = daura.Replace("ô", "o");
           daura = daura.Replace("ố", "o");
           daura = daura.Replace("ồ", "o");
           daura = daura.Replace("ổ", "o");
           daura = daura.Replace("ỗ", "o");
           daura = daura.Replace("ộ", "o");
           daura = daura.Replace("ơ", "o");
           daura = daura.Replace("ờ", "o");
           daura = daura.Replace("ớ", "o");
           daura = daura.Replace("ở", "o");
           daura = daura.Replace("ỡ", "o");
           daura = daura.Replace("ợ", "o");
           daura = daura.Replace("í", "i");
           daura = daura.Replace("ì", "i");
           daura = daura.Replace("ỉ", "i");
           daura = daura.Replace("ĩ", "i");
           daura = daura.Replace("ị", "i");
           daura = daura.Replace("ý", "y");
           daura = daura.Replace("ỳ", "y");
           daura = daura.Replace("ỷ", "y");
           daura = daura.Replace("ỹ", "y");
           daura = daura.Replace("ỵ", "y");
           daura = daura.Replace("é", "e");
           daura = daura.Replace("è", "e");
           daura = daura.Replace("ẻ", "e");
           daura = daura.Replace("ẽ", "e");
           daura = daura.Replace("ẹ", "e");
           daura = daura.Replace("ê", "e");
           daura = daura.Replace("ế", "e");
           daura = daura.Replace("ề", "e");
           daura = daura.Replace("ể", "e");
           daura = daura.Replace("ễ", "e");
           daura = daura.Replace("ệ", "e");
           daura = daura.Replace("ú", "u");
           daura = daura.Replace("ù", "u");
           daura = daura.Replace("ủ", "u");
           daura = daura.Replace("ũ", "u");
           daura = daura.Replace("ụ", "u");
           daura = daura.Replace("ư", "u");
           daura = daura.Replace("ừ", "u");
           daura = daura.Replace("ứ", "u");
           daura = daura.Replace("ử", "u");
           daura = daura.Replace("ữ", "u");
           daura = daura.Replace("ự", "u");
           daura = daura.Replace(",", "-");
           daura = daura.Replace(".", "-");
           daura = daura.Replace(";", "-");
           daura = daura.Replace(":", "-");
           daura = daura.Replace("?", "-");
           daura = daura.Replace("<", "-");
           daura = daura.Replace(">", "-");
           daura = daura.Replace("`", "");
           daura = daura.Replace("~", "-");
           daura = daura.Replace("!", "-");
           daura = daura.Replace("@", "-");
           daura = daura.Replace("#", "-");
           daura = daura.Replace("$", "-");
           daura = daura.Replace("%", "-");
           daura = daura.Replace("^", "-");
           daura = daura.Replace("&", "-");
           daura = daura.Replace("*", "-");
           daura = daura.Replace("(", "-");
           daura = daura.Replace(")", "-");
           //daura = daura.Replace("-", "_");
           daura = daura.Replace("+", "-");
           daura = daura.Replace("=", "-");
           daura = daura.Replace("\\", "-");
           daura = daura.Replace("|", "-");
           daura = daura.Replace("[", "-");
           daura = daura.Replace("]", "-");
           daura = daura.Replace("{", "-");
           daura = daura.Replace("}", "-");
           daura = daura.Replace("/", "-");
           daura = daura.Replace("'", "");
           daura = daura.Replace("\"", "-");

           return daura;
       }
       #endregion

       #region selected gia tri cua droplist
       public static void SetSelected(DropDownList dropList, string selectedValue)
       {
           dropList.SelectedIndex = -1;
           SetSelected(dropList.Items, selectedValue);
       }

       public static void SetSelected(ListItemCollection lstItems, string selectedValue)
       {
           ListItem item = lstItems.FindByValue(selectedValue);
           if (item != null) item.Selected = true;
       }
       public static void FillIndex(DropDownList dropIndex, int min, int max, int selected)
       {
           if (max == 0) max = 1;
           dropIndex.Items.Clear();
           for (int i = min; i <= max; i++)
           {
               ListItem item = new ListItem(i.ToString(), i.ToString());
               if (i == selected) item.Selected = true;
               else item.Selected = false;
               dropIndex.Items.Add(item);
           }
       }
       #endregion
      
       public static string GetCPPage(string ctrlKey, string[] paramsName, string[] paramsValue)
       {
           StringBuilder sb = new StringBuilder(ObjConstants.DEFAULT_CP_PAGE);
           //sb.Append("?portalid="); sb.Append(_portalId);
           sb.Append("?ctrlkey="); sb.Append(ctrlKey);
           if (paramsName != null)
           {
               for (int i = 0; i < paramsName.Length; i++)
               {
                   sb.Append("&"); sb.Append(paramsName[i]); sb.Append("="); sb.Append(paramsValue[i]);
               }
           }
           return sb.ToString();
       }
      
       public static string StringIndent(int level)
       {
           string retVal = string.Empty;
           for (int i = 0; i < level; i++)
               retVal += "...";
           return retVal;
       }

       public static string strInitImage(string image, int width, int height)
       {
           StringBuilder retVal = new StringBuilder();
           retVal.Append("<img border=\"0\" alt=\"Ảnh quảng cáo\" class=\"image_advertisement\" src=\"" + image + "\"");
           if (width > 0) retVal.Append(" width=\"" + width + "px\" ");
           if (height > 0) retVal.Append(" height=\"" + height + "px\" ");
           retVal.Append("/>");
           return retVal.ToString();
       }

       public static string strInitFlash(string flashURL, int width, int height)
       {
           StringBuilder retVal = new StringBuilder();
           retVal.Append("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" id=\"obj1\" ");
           retVal.Append(" codebase =\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " + " border=\"0\" ");
           if (width != 0) retVal.Append(" width=\"" + width + "\"");
           if (height != 0) retVal.Append(" height=\"" + height + "\"");
           retVal.Append(">");
           retVal.Append(" <param name=\"movie\" value=\"" + flashURL + "\"/> ");
           retVal.Append(" <param name=\"quality\" value=\"High\"/> ");
           retVal.Append(" <param name=\"wmode\" value=\"transparent\"/> ");
           retVal.Append("<embed src=\"" + flashURL + "\"  wmode=\"transparent\"  ");

           retVal.Append(" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" name=\"obj1\" ");
           // neu gia tri chieu ngang , rong khac 0, set thuoc tinh chieu ngang, rong
           if (width != 0) retVal.Append(" width=\"" + width + "\"");
           if (height != 0) retVal.Append(" height=\"" + height + "\"");
           retVal.Append("/>");
           retVal.Append("</object> ");
           return retVal.ToString();
       }
       public static string strInitFlash(string flashURL, string _link, int width, int height)
       {
           StringBuilder retVal = new StringBuilder();
           retVal.Append("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" id=\"obj1\" ");
           retVal.Append(" codebase =\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " + " border=\"0\" ");
           if (width != 0 && height != 0)
           {
               retVal.Append(" width=\"" + width + "\"");
               retVal.Append(" height=\"" + height + "\"");
           }
           retVal.Append(">");
           retVal.Append(" <param name=\"movie\" value=\"" + flashURL + "\"/> ");
           retVal.Append(" <param name=\"quality\" value=\"High\"/> ");
           retVal.Append(" <param name=\"wmode\" value=\"transparent\"/> ");
           retVal.Append(" <param name=\"AllowScriptAccess\" value=\"always\"/> ");
           retVal.Append(" <param name=\"FlashVars\" value=\"link=" + _link + "\"/> ");
           retVal.Append("<embed allowscriptaccess=\"always\" wmode=\"transparent\" src=\"" + flashURL + "\"  flashvars=\"link=" + _link + "\" ");

           retVal.Append(" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" ");
           // neu gia tri chieu ngang , rong khac 0, set thuoc tinh chieu ngang, rong
           if (width != 0 && height != 0)
           {
               retVal.Append(" width=\"" + width + "\"");
               retVal.Append(" height=\"" + height + "\"");
           }
           retVal.Append("/>");
           retVal.Append("</object> ");
           return retVal.ToString();
       }
       public static string strInitMovie(string mediaPath, int width, int height)
       {
           StringBuilder retVal = new StringBuilder();
           retVal.Append(
               "<object classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" id=\"mediaPlayer\" type=\"application/x-oleobject\" ");
           retVal.Append(
               " codebase =\"'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'\" " +
               " border=\"0\" ");
           if (width != 0 && height != 0)
           {
               retVal.Append(" width=\"" + width + "\"");
               retVal.Append(" height=\"" + height + "\"");
           }

           retVal.Append(">");
           retVal.Append(" <param name=\"fileName\" value=\"" + mediaPath + "\"/> ");
           retVal.Append(" <param name=\"uiMode\" value=\"none\"/> ");
           retVal.Append(" <param name=\"autostart\" value=\"true\"/> ");
           retVal.Append(" <param name=\"showControls\" value=\"false\"/> ");

           retVal.Append("<EMBED pluginspage=\"http://microsoft.com/windows/mediaplayer/en/download/\" id=\"mediaPlayer\" name=\"mediaPlayer\" ");
           if (width != 0 && height != 0)
           {
               retVal.Append(" width=\"" + width + "\"");
               retVal.Append(" height=\"" + height + "\"");
           }
           retVal.Append(" src=\"" + mediaPath + "\" type=\"application/x-mplayer2\" displaysize=\"4\" autosize=\"-1\"  showcontrols=\"0\" showtracker=\"0\" showdisplay=\"0\" showstatusbar=\"0\" videoborder3d=\"-1\" uiMode=\"none\" autostart=\"true\" designtimesp=\"5311\"   ></embed>");
           retVal.Append("</object>");
           return retVal.ToString();
       }

    }
}
